<template>
	<view style="background-color: #f2f2f2;">
		<view class="distribution">
			<u-row justify="space-between" gutter="10">
				<u-col span="4">
					<view class="ones ayout" @click="release">
						<image src="@/static/index/homeowner/homeowner1.png " style="width: 70rpx;height: 70rpx;"
							mode="widthFix"></image>
						<view class="">发布房源</view>
					</view>
				</u-col>
				<u-col span="4">
					<view class="twos ayout" @click="history">
						<image src="@/static/index/homeowner/homeowner2.png " style="width: 70rpx;height: 70rpx;"
							mode="widthFix"></image>
						<view class="">历史发布</view>
					</view>
				</u-col>
				<u-col span="4">
					<view class="threes ayout" @click="agreement">
						<image src="@/static/index/homeowner/homeowner3.png " style="width: 70rpx;height: 70rpx;"
							mode="widthFix"></image>
						<view class="">我的租约</view>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="distribution">
			<u-dropdown ref="uDropdownRef">
				<u-dropdown-item title="小区" :height="300">
					<!-- <view class="slotContent" style="background-color: #FFFFFF;"> -->
					<scroll-view scroll-y="true" style="background-color: #FFFFFF;height: 300rpx;">
						<view v-for="(item,index) in communityvalue" :key="index"
							@click="communityclick(item.villageId)">
							<view class="option">{{item.villageName}}
							</view>
							<u-line color="#666666"></u-line>
						</view>
					</scroll-view>
				</u-dropdown-item>
				<u-dropdown-item title="户型" :height="300">
					<scroll-view scroll-y="true" style="background-color: #FFFFFF;height: 300rpx;">
						<view v-for="(item,index) in housetypeValue" :key="index" @click="housetypeclick(item)">
							<view class="option">{{item}}
							</view>
							<u-line color="#666666"></u-line>
						</view>
					</scroll-view>
				</u-dropdown-item>
				<u-dropdown-item title="租金">
					<scroll-view scroll-y="true" style="background-color: #FFFFFF;height: 300rpx;">
						<view v-for="(item,index) in rental" :key="index" @click="rentalclick(item)">
							<view class="option">{{item.value}}
							</view>
							<u-line color="#666666"></u-line>
						</view>
					</scroll-view>
				</u-dropdown-item>
				<u-dropdown-item title="租期">
					<scroll-view scroll-y="true" style="background-color: #FFFFFF;height: 300rpx;">
						<view v-for="(item,index) in leaseTerm" :key="index" @click="leaseTermclick(item)">
							<view class="option">{{item.value}}
							</view>
							<u-line color="#666666"></u-line>
						</view>
					</scroll-view>
				</u-dropdown-item>
				<u-dropdown-item title="排序">
					<scroll-view scroll-y="true" style="background-color: #FFFFFF;height: 300rpx;">
						<view @click="entire">
							<view class="option">全部
							</view>
							<!-- <u-line color="#666666"></u-line> -->
						</view>
					</scroll-view>
				</u-dropdown-item>
			</u-dropdown>
		</view>
	</view>
</template>

<script>
	// 注下拉还没完成，不过可以根据官网的插槽完成
	import {
		onMounted,
	} from 'vue';
	import {
		post,
		get
	} from '@/serve/method.js'
	import {
		test
	} from '@/uni_modules/uview-plus';
	export default {
		props: ['parentData'],
		data() {
			return {
				// 下拉菜单
				// 小区
				communityvalue: [],
				// 房型
				housetypeValue: ['二室一厅', '三室一厅', '一室一厅', '一室二厅', '一室三厅', '二室二厅', '二室三厅', '三室二厅', '三室三厅', '四室一厅', '四室二厅',
					'四室三厅'
				],
				// 租金
				rental: [{
					'value': "800以下",
					'title': 1
				}, {
					'value': "800-1000",
					'title': 2
				}, {
					'value': "1000-1500",
					'title': 3
				}, {
					'value': "1500-2000",
					'title': 3
				}, {
					'value': "2000-3000",
					'title': 3
				}, {
					'value': "3000以上",
					'title': 4
				}],
				// 租期
				leaseTerm: [{
					'value': "一个月",
					'title': 1
				}, {
					'value': "三个月",
					'title': 3
				}, {
					'value': "六个月",
					'title': 6
				}, {
					'value': "一年",
					'title': 12
				}],
				// 以上为下拉菜单
				flowList: [],
				uWaterfall: '',
				pageNum: 1,
				pageSize: 20,
				houseList: []
			}
		},
		mounted() {
			this.community()
		},
		methods: {
			// 获取小区
			community() {
				let urls = '/api/house/selectAllSearch'
				get(urls).then((res) => {
					this.communityvalue = res.data.villageList
					console.log(this.communityvalue, '获取小区')
				})
			},
			communityclick(id) {
				// this.villageId = id
				// this.flowList.length = 0
				// this.pageNum = 1
				// this.findHouseList(1);
				this.$emit('child-event', id);
				this.$refs.uDropdownRef.close();
			},
			// 以上为获取小区
			// 房型
			housetypeclick(item) {
				// this.houseNum = item.substring(0, 2)
				// this.houseHall = item.substring(2, 4)
				// this.flowList.length = 0
				// this.pageNum = 1
				// this.findHouseList(1);
				this.$emit('child-eventone', item);
				this.$refs.uDropdownRef.close();
			},
			// 以上为房型
			// 租金
			rentalclick(item) {
				// console.log(item)
				// if (item.title == 1) {
				// 	this.maxPrice = item.value.substring(0, 3)
				// 	this.minPrice = null
				// }
				// if (item.title == 2) {
				// 	this.maxPrice = item.value.substring(4, 9)
				// 	this.minPrice = item.value.substring(0, 3)
				// }
				// if (item.title == 3) {
				// 	this.minPrice = item.value.substring(0, 4)
				// 	this.maxPrice = item.value.substring(5, 10)
				// }
				// if (item.title == 4) {
				// 	this.maxPrice = null
				// 	this.minPrice = item.value.substring(0, 4)
				// }
				// this.flowList.length = 0
				// this.pageNum = 1
				// this.findHouseList(1);
				this.$emit('child-eventtwo', item);
				this.$refs.uDropdownRef.close();
			},
			// 租期
			leaseTermclick(item) {
				this.$emit('child-eventthree', item);
				this.$refs.uDropdownRef.close();
			},
			// 全部
			entire() {
				this.$emit('child-eventfour');
				this.$refs.uDropdownRef.close();
			},
			// 以上为选择
			history() {
				console.log("历史发布")
				uni.navigateTo({
					url: '/pages/publishlease/lease?id=历史发布'
				});
			},
			agreement() {
				console.log("我的租约")
				uni.navigateTo({
					url: '/pages/publishlease/lease?id=我的租约'
				});
			},
			release() {
				if (this.parentData == 'false') {
					// uni.showModal({
					// 	title: '提示',
					// 	content: '是否微信授权登录',
					// 	success: function(res) {
					// 		if (res.confirm) {
					// 			uni.redirectTo({
					// 				url: '/pages/index/register'
					// 			});
					// 		} else if (res.cancel) {
					// 			console.log('用户点击取消');
					// 		}
					// 	}
					// });
					console.log(999)
					this.$emit('judgmentshow');
				} else {
					uni.getStorage({
						key: 'lifeData',
						success: function(res) {
							let url = "/api/user/selectUserById"
							get(url, {
								userId: res.data.vuex_user.userId
							}).then((res) => {
								console.log(res.data.authStatus, "验证")
								if (res.data.authStatus !== "2" && res.data.authStatus !== "1") {
									uni.navigateTo({
										url: '/pages/mine/authentication'
									});
								} else {
									uni.navigateTo({
										url: '/pages/detail/addHouse'
									});
								}
							})
						},
						fail: function(res) {
							if (res.errMsg == 'getStorage:fail data not found') {
								uni.reLaunch({
									url: '/pages/index/index'
								});
							}
						}
					})
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.ayout {
		display: flex;
		align-items: center;
		border-radius: 8px;
		font-size: 13px;
		font-weight: bold;
		padding: 2px 0;
	}

	.distribution {
		padding: 0 4vw;

		.option {
			padding: 8px 15px;
			color: #666666;
		}

		.ones {
			background-color: #F5E8E2;
		}

		.twos {
			background-color: #E6F0F1;
		}

		.threes {
			background-color: #E7EEF6;
		}
	}

	.demo-warter {
		border-radius: 8px;
		margin-top: 3px;
		background-color: #ffffff;
		padding: 3px;
		position: relative;
	}
</style>